package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.base.ContractBaseEnum;
import lombok.Getter;

import java.util.Objects;

@Getter
public enum WaitOutstockEnum {

    PRODUCT_IMGS("file_1","enum.product.attrName.product_imgs",FieldTypeEnum.IMAGE.getType(),"productImgs", XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),1),
    PRODUCT_NAME("productName","enum.selectProduct.attrName.product_name",FieldTypeEnum.TEXT.getType(),"product_name",XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),2),
    PRODUCT_NO("productNo","enum.selectProduct.attrName.product_no",FieldTypeEnum.TEXT.getType(),"product_no",XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),3),
    SPECIFICATION("specification","enum.selectProduct.attrName.specification",FieldTypeEnum.TEXT.getType(),"specification",XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),4),
    UNIT("text_8","enum.waitOutstock.attrName.unit",FieldTypeEnum.COMBO.getType(),"product_unit",XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),5),
    WAIT_OUTSTOCK_NUM(SelectProductEnum.WAIT_OUTSTOCK_NUM.getAttr(),"enum.waitOutstock.attrName.wait_outstock_num",FieldTypeEnum.NUM.getType(),"product_num",XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),6),
    STOCK("num_12","enum.selectProduct.attrName.stock",FieldTypeEnum.NUM.getType(),"stock",XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),7),
    MEMO("memo","enum.selectProduct.attrName.memo",FieldTypeEnum.TEXTAREA.getType(),"memo",XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),8),
    CONTRACT_NO(ContractBaseEnum.CONTRACT_NO.getAttr(), "enum.contract.attrName.contract_no",  FieldTypeEnum.SERIALNO.getType(),"serialNo",XbbRefTypeEnum.CONTRACT.getCode(),9),
    NAME("text_1", "enum.contract.attrName.name", FieldTypeEnum.TEXT.getType(),"text_1",XbbRefTypeEnum.CONTRACT.getCode(),10),
    LINK_CUSTOMER(ContractBaseEnum.LINK_CUSTOMER.getAttr(), "enum.contract.attrName.link_customer", FieldTypeEnum.TEXT.getType(),"text_2",XbbRefTypeEnum.CONTRACT.getCode(),11),
    SIGN_TIME(ContractBaseEnum.SIGN_TIME.getAttr(), "enum.contract.attrName.sign_time", FieldTypeEnum.DATETIME.getType(),"date_1",  XbbRefTypeEnum.CONTRACT.getCode(),12),
    STATUS(ContractBaseEnum.STATUS.getAttr(), "enum.contract.attrName.status", FieldTypeEnum.COMBO.getType(),"status",  XbbRefTypeEnum.CONTRACT.getCode(),13),
    OWNER_ID(ContractBaseEnum.OWNER_ID.getAttr(), "enum.contract.attrName.owner_id", FieldTypeEnum.OWNERID.getType(),"ownerId",  XbbRefTypeEnum.CONTRACT.getCode(),14),
    MINOR_USER(ContractBaseEnum.MINOR_USER.getAttr(), "enum.contract.attrName.minor_user", FieldTypeEnum.TEXT.getType(),"coUserId",  XbbRefTypeEnum.CONTRACT.getCode(),15),
    CREATOR_ID(ContractBaseEnum.CREATOR_ID.getAttr(), "enum.contract.attrName.creator_id",FieldTypeEnum.CREATORID.getType(),"creatorId",  XbbRefTypeEnum.CONTRACT.getCode(),16),
    ADD_TIME(ContractBaseEnum.ADD_TIME.getAttr(), "enum.contract.attrName.add_time", FieldTypeEnum.ADDTIME.getType(),"addTime",  XbbRefTypeEnum.CONTRACT.getCode(),17),
    UPDATE_TIME(ContractBaseEnum.UPDATE_TIME.getAttr(), "enum.contract.attrName.update_time", FieldTypeEnum.UPDATETIME.getType(),"updateTime",  XbbRefTypeEnum.CONTRACT.getCode(),18),
    WAIT_INSTOCK_PRODUCT("option_9","enum.listOption.attrName.wait_outstock_product",FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(),"waitOutstockProduct",XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),19),

    ;

    private String attr;

    private String attrName;

    private Integer fieldType;

    private String saasAttr;

    private Integer linkedType;

    private Integer sort;

    WaitOutstockEnum(String attr, String attrName, Integer fieldType, String saasAttr, int linkedType, int sort) {
        this.attr = attr;
        this.attrName = attrName;
        this.fieldType = fieldType;
        this.saasAttr = saasAttr;
        this.linkedType = linkedType;
        this.sort = sort;
    }
    public static Integer getSortByWaitInstockSort(String attr){
        for (WaitOutstockEnum waitOutstockEnum : WaitOutstockEnum.values()){
            if (Objects.equals(attr,waitOutstockEnum.getAttr())){
                return waitOutstockEnum.getSort();
            }
        }
        return 0 ;
    }

    public static Boolean isProductSort (String attr){
        Boolean isProduct = true;
        for (WaitOutstockEnum waitInstockEnum : WaitOutstockEnum.values()){
            if (Objects.equals(attr,waitInstockEnum.getAttr())){
                Integer linkedType = waitInstockEnum.getLinkedType();
                if (Objects.equals(linkedType,XbbRefTypeEnum.CONTRACT.getCode())){
                    isProduct =  false;
                }
            }
        }
        return isProduct;
    }

    public static String getFeildName(String attr){
        for (WaitOutstockEnum waitOutstockEnum : WaitOutstockEnum.values()){
            if (Objects.equals(attr,waitOutstockEnum.getAttr())){
                return waitOutstockEnum.getSaasAttr();
            }
        }
        return "update_time";
    }


    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }



}
